import { CableClass } from "./conn/CableClass";
import { I2C } from "./conn/I2C";
import { SPI } from "./conn/SPI";
import { UART } from "./conn/UART";
import { Stud } from "./Stud";

// gpio 用途
export enum  Usage{

    vcc = "vcc" ,
    vdd = "vdd" ,
    vm = "vm" ,
    ground = "ground" ,
    reset = "reset",

    uartmosi = "uart.mosi" ,            // master tx, slaver rx
    uartmiso = "uart.miso" ,            // master rx, slaver tx
    
    i2cscl = "i2c.scl" ,
    i2csda = "i2c.sda" ,

    spisck = "spi.sck" ,
    spimosi = "spi.mosi" ,
    spimiso = "spi.miso" ,
    spics = "spi.cs" ,

    // gpio
    adc = "adc" ,
    gpioinput = "i" ,
    gpiooutput = "o" ,
    pwm = "pwm" ,

    none = "none" ,
}

export function isGPIOPin(pin: Stud|null) {
    if(!pin)
        return false
    return pin.info.usages.includes(Usage.gpioinput) || pin.info.usages.includes(Usage.gpiooutput)
}

export function isSeiralUsage(usage: Usage): CableClass|false {
    if(usage.substr(0,5)=='uart.')
        return UART
    else if(usage.substr(0,4)=='i2c.')
        return I2C
    else if(usage.substr(0,4)=='spi.')
        return SPI
    else
        return false
}